import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:material_collection_app/utils/utils.dart';

class CheckDialogResult extends StatefulWidget {
  final int materialLength;
  final int matchingNum;
  final int noMatchingNum;
  final bool checkStatus;
  final onSubmit;

  CheckDialogResult(
      {Key key,
      this.materialLength,
      this.matchingNum,
      this.noMatchingNum,
      this.checkStatus,
      this.onSubmit})
      : super(key: key);

  @override
  State<StatefulWidget> createState() => CheckDialogResultState();
}

class CheckDialogResultState extends State<CheckDialogResult> {
  TextEditingController _remarkController = new TextEditingController();

  @override
  void initState() {
    super.initState();
  }

  Widget _buildDialogHead(title) {
    return Container(
      height: 80.w,
      decoration: BoxDecoration(
          color: Utils.hexToColor('#F7F7F7'),
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(12.w), topRight: Radius.circular(12.w))),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(left: 31.w),
            child: Text(title,
                style: TextStyle(
                    color: Utils.hexToColor('#333333'),
                    fontSize: 16,
                    fontWeight: FontWeight.bold)),
          ),
          InkWell(
            onTap: () {
              Navigator.of(context).pop();
            },
            child: Container(
              padding: EdgeInsets.fromLTRB(30.w, 24.w, 30.w, 24.w),
              alignment: Alignment.topRight,
              child: Image.asset(
                'assets/dialog_close.png',
                width: 36.w,
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _buildRow(String title, int number) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 18),
      decoration: BoxDecoration(
          border: Border(
              bottom:
                  BorderSide(width: 1, color: Utils.hexToColor('#E6E6E6')))),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Text(
            title,
            style: TextStyle(color: Utils.hexToColor('#808080'), fontSize: 14),
          ),
          Text(number.toString(),
              style: TextStyle(
                  color: Utils.hexToColor('#333333'),
                  fontSize: 15,
                  fontWeight: FontWeight.bold)),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);

    return Container(
        width: 700.w,
        height: 1161.w,
        decoration:
            BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(100))),
        child: Column(
          children: <Widget>[
            _buildDialogHead('盘点结果'),
            Expanded(
              flex: 1,
              child: SingleChildScrollView(
                child: Container(
                    padding: EdgeInsets.fromLTRB(20, 0, 20, 20),
                    child: Column(
                      children: <Widget>[
                        _buildRow('盘点物资数', widget.materialLength),
                        _buildRow('匹配物资数', widget.matchingNum),
                        _buildRow('有误物资数', widget.noMatchingNum),
                        Container(
                          padding: EdgeInsets.symmetric(vertical: 13),
                          decoration: BoxDecoration(
                              border: Border(
                                  bottom: BorderSide(
                                      width: 1,
                                      color: Utils.hexToColor('#E6E6E6')))),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: <Widget>[
                              Text(
                                '盘点结果',
                                style: TextStyle(
                                    color: Utils.hexToColor('#808080'),
                                    fontSize: 14),
                              ),
                              Row(
                                children: <Widget>[
                                  Text(widget.checkStatus == true ? '盘盈' : '盘亏',
                                      style: TextStyle(
                                          color: Utils.hexToColor(
                                              widget.checkStatus == true
                                                  ? '#00AB9D'
                                                  : '#F54745'),
                                          fontSize: 15,
                                          fontWeight: FontWeight.bold))
                                ],
                              )
                            ],
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(top: 20),
                          child: TextField(
                            maxLines: 4,
                            controller: _remarkController,
                            style: TextStyle(
                                fontSize: 14, color: Colors.black), //输入文本的样式
                            decoration: InputDecoration(
                              hintText: "盘点备注~",
                              hintStyle: TextStyle(
                                  color: Utils.hexToColor('#B3B3B3'),
                                  fontSize: 14),
                              contentPadding:
                                  EdgeInsets.fromLTRB(21.w, 10, 21.w, 10),
                              fillColor: Colors.white,
                              filled: true,
                              enabledBorder: OutlineInputBorder(
                                borderRadius: BorderRadius.all(
                                  Radius.circular(8.w),
                                ),
                                borderSide: BorderSide(
                                  color: Utils.hexToColor('#D4D4D4'),
                                  width: 1,
                                ),
                              ),
                              focusedBorder: OutlineInputBorder(
                                borderSide: BorderSide(
                                  color: Utils.hexToColor('#D4D4D4'),
                                  width: 1,
                                ),
                                borderRadius: BorderRadius.all(
                                  Radius.circular(8.w),
                                ),
                              ),
                            ),
                          ),
                        ),
                      ],
                    )),
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  width: 270.w,
                  height: 120.w,
                  // color: Utils.hexToColor('#FFFFFF'),
                  margin: EdgeInsets.only(right: 40.w),
                  alignment: Alignment.center,
                  child: SizedBox(
                    width: 620.w,
                    height: 76.w,
                    child: ElevatedButton(
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                      child: Text(
                        '重新盘点',
                        style: TextStyle(color: Colors.white),
                      ),
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Utils.hexToColor('#FF9232'),
                        shape: RoundedRectangleBorder(
                            borderRadius:
                                BorderRadius.all(Radius.circular(60.w))),
                      ),
                    ),
                  ),
                ),
                Container(
                  width: 270.w,
                  height: 120.w,
                  // color: Utils.hexToColor('#FFFFFF'),
                  alignment: Alignment.center,
                  child: SizedBox(
                    width: 620.w,
                    height: 76.w,
                    child: ElevatedButton(
                      onPressed: () {
                        widget.onSubmit(_remarkController.text.trim());
                      },
                      child: Text(
                        '确定',
                        style: TextStyle(color: Colors.white),
                      ),
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Utils.hexToColor('#297CFF'),
                        shape: RoundedRectangleBorder(
                            borderRadius:
                                BorderRadius.all(Radius.circular(60.w))),
                      ),
                    ),
                  ),
                )
              ],
            )
          ],
        ));
  }
}
